/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Listados.java
 *
 * Created on 23/11/2011, 01:07:41 PM
 */
package Interface;

import Dominio.Controladora;
import Dominio.Empresa;
import java.awt.print.PrinterException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTable;

/**
 *
 * @author Agustin
 */
public class Listados extends javax.swing.JFrame {

    private static Listados instance;

    public static Listados getInstance() {
        if (instance == null) {
            instance = new Listados();
        }
        instance.cargarcobo();
        return instance;
    }

    public void cargarcobo() {
        ModeloComboEmpresas em = new ModeloComboEmpresas();
        cmbEmpresas.setModel(em);
    }

    /** Creates new form Listados */
    public Listados() {
        initComponents();
        this.setLocationRelativeTo(null);
        cargarcobo();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblListados = new javax.swing.JLabel();
        cmbEmpresas = new javax.swing.JComboBox();
        btnPantalla = new javax.swing.JButton();
        rbtnListadoUsuarios = new javax.swing.JRadioButton();
        rbtnListadoEmpleados = new javax.swing.JRadioButton();
        rbtnListadoEmpresas = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        lblListados.setFont(new java.awt.Font("Monospaced", 0, 24));
        lblListados.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblListados.setText("Listados");

        cmbEmpresas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btnPantalla.setText("Listar");
        btnPantalla.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPantallaActionPerformed(evt);
            }
        });

        rbtnListadoUsuarios.setText("Listado de Usuarios");
        rbtnListadoUsuarios.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                rbtnListadoUsuariosItemStateChanged(evt);
            }
        });

        rbtnListadoEmpleados.setText("Listado de Empleados");
        rbtnListadoEmpleados.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                rbtnListadoEmpleadosItemStateChanged(evt);
            }
        });

        rbtnListadoEmpresas.setText("Listado de Empresas");
        rbtnListadoEmpresas.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                rbtnListadoEmpresasItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblListados, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rbtnListadoEmpresas)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(rbtnListadoUsuarios)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnPantalla))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(rbtnListadoEmpleados)
                            .addGap(18, 18, 18)
                            .addComponent(cmbEmpresas, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(lblListados)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(rbtnListadoEmpleados)
                    .addComponent(cmbEmpresas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addComponent(rbtnListadoEmpresas)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbtnListadoUsuarios)
                    .addComponent(btnPantalla))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void rbtnListadoEmpleadosItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_rbtnListadoEmpleadosItemStateChanged
        if (rbtnListadoEmpleados.isSelected()) {
            rbtnListadoEmpresas.setEnabled(false);
            rbtnListadoUsuarios.setEnabled(false);
        } else {
            rbtnListadoEmpresas.setEnabled(true);
            rbtnListadoUsuarios.setEnabled(true);
        }

    }//GEN-LAST:event_rbtnListadoEmpleadosItemStateChanged

    private void btnPantallaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPantallaActionPerformed
        try {
            if (rbtnListadoEmpleados.isSelected()) {
                if (cmbEmpresas.getSelectedItem() != null) {
                    if (!cmbEmpresas.getSelectedItem().toString().equals("")) {
                        Empresa e = (Empresa) cmbEmpresas.getSelectedItem();
                        ListadoEmpleados.getInstance(e.getRut()).setVisible(true);
                    }
                } else {
                    throw new Exception("Debe seleccionar alguna empresa.");
                }
            } else if (rbtnListadoEmpresas.isSelected()) {
                ListadoEmpresas.getInstance().setVisible(true);
            } else {
                ListadoUsuarios.getInstance().setVisible(true);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, Controladora.getInstance().limpiarE(e), "Atencion", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnPantallaActionPerformed

    private void rbtnListadoEmpresasItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_rbtnListadoEmpresasItemStateChanged
        if (rbtnListadoEmpresas.isSelected()) {
            rbtnListadoEmpleados.setEnabled(false);
            rbtnListadoUsuarios.setEnabled(false);
        } else {
            rbtnListadoEmpleados.setEnabled(true);
            rbtnListadoUsuarios.setEnabled(true);
        }
    }//GEN-LAST:event_rbtnListadoEmpresasItemStateChanged

    private void rbtnListadoUsuariosItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_rbtnListadoUsuariosItemStateChanged
        if (rbtnListadoUsuarios.isSelected()) {
            rbtnListadoEmpleados.setEnabled(false);
            rbtnListadoEmpresas.setEnabled(false);
        } else {
            rbtnListadoEmpleados.setEnabled(true);
            rbtnListadoEmpresas.setEnabled(true);
        }
    }//GEN-LAST:event_rbtnListadoUsuariosItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Listados().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnPantalla;
    private javax.swing.JComboBox cmbEmpresas;
    private javax.swing.JLabel lblListados;
    private javax.swing.JRadioButton rbtnListadoEmpleados;
    private javax.swing.JRadioButton rbtnListadoEmpresas;
    private javax.swing.JRadioButton rbtnListadoUsuarios;
    // End of variables declaration//GEN-END:variables
}
